package com.weilx959.spt.plugin.e2sp.constant;

import com.weilx959.spt.plugin.e2sp.utils.sql.deparser.DeleteSQLDeParser;
import com.weilx959.spt.plugin.e2sp.utils.sql.deparser.InsertSQLDeParser;
import com.weilx959.spt.plugin.e2sp.utils.sql.deparser.SQLDeParser;
import com.weilx959.spt.plugin.e2sp.utils.sql.parser.CheckSQLParser;
import com.weilx959.spt.plugin.e2sp.utils.sql.parser.DeleteSQLParser;
import com.weilx959.spt.plugin.e2sp.utils.sql.parser.InsertSQLParser;
import com.weilx959.spt.plugin.e2sp.utils.sql.parser.SQLParser;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.sf.jsqlparser.statement.Statement;
import net.sf.jsqlparser.statement.delete.Delete;
import net.sf.jsqlparser.statement.insert.Insert;
import net.sf.jsqlparser.statement.select.Select;
import net.sf.jsqlparser.statement.update.Update;

/**
 * sql类型枚举
 *
 * @author weilx
 * @since 2024-05-02
 */
@Getter
@RequiredArgsConstructor
public enum SQLType {
    DELETE(0, new DeleteSQLParser(), new DeleteSQLDeParser(), Delete.class),
    INSERT(1, new InsertSQLParser(), new InsertSQLDeParser(), Insert.class),
    SELECT(2, null, null, Select.class),
    UPDATE(3, null, null, Update.class),
    CHECK(4, new CheckSQLParser(), null, null),
    ERROR(99, null, null, null);

    private final int sort;

    private final SQLParser parser;

    private final SQLDeParser deParser;

    private final Class<? extends Statement> ccjStatementClass;

    public static SQLType getSQLType(Class<? extends Statement> ccjStatementClass) {
        for (SQLType sqlType : SQLType.values()) {
            if (sqlType.ccjStatementClass == ccjStatementClass) {
                return sqlType;
            }
        }
        return null;
    }
}
